{extend name='table'}

{block name="content"}
<div class="layui-tab layui-tab-card">
    <div class="layui-tab-content">
        <form class="layui-form layui-form-pane form-search" action="{:sysuri()}" onsubmit="return false" method="get" autocomplete="off">

            {include file='search', type="index"}

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">{:lang('状态')}</label>
                <div class="layui-input-inline">
                    <select name="status" class="layui-select">
                        <option value="">全部</option>
                        <option value="2">待集包</option>
                        <option value="3">已集包</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">{:lang('创建时间')}</label>
                <div class="layui-input-inline">
                    <input data-date-range name="create_at" value="" placeholder="{:lang('请选择创建时间')}" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> {:lang('搜 索')}</button>
            </div>
        </form>
        <table id="UserTable" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
    </div>
</div>
<script>
    var maxWidth = window.innerWidth;
    var maxHeight = window.innerHeight;

    var account_show = {$account_show};

    $(function () {
        let table = layui.table;
        $('#UserTable').layTable({
            even: true, height: 'full',
            toolbar: '#toolbar',
            where: {type: '{$type|default="index"}'},
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'warehouse_name', title: '{:lang("仓库")}', minWidth: 150, align: 'center'},
                // {field: 'platform_name', title: '{:lang("平台")}', minWidth: 150, align: 'center', hide:!account_show},
                {field: 'account_name', title: '{:lang("公司")}', minWidth: 150, align: 'center'},
                {field: 'order_no', title: '{:lang("订单号")}', minWidth: 150, align: 'center'},
                {field: 'express_company', title: '{:lang("物流公司")}', minWidth: 100, align: 'center'},
                {field: 'express_no', title: '{:lang("合箱单号")}', minWidth: 150, align: 'center'},
                {field: 'location_code', title: '{:lang("货位")}', align: 'center', minWidth: 120},
                {field: 'status_name', title: '{:lang("状态")}', align: 'center', minWidth: 120},
                {field: 'into_time', title: '{:lang("入库时间")}', align: 'center', minWidth: 150},
                {toolbar: '#operator_bar', title: '{:lang("操作面板")}', align: 'center', minWidth: 260, fixed: 'right'}
            ]]
        });

        table.on('tool(UserTable)', function(obj) {
            let data = obj.data;
            if(obj.event === 'print_btn') { // 打印合箱码
                if(!isNotEmpty(data.order_no)) {
                    layer.msg('{:lang("合箱单号不存在，打印失败")}', {icon: 2});
                    return false;
                }
                //初始化打印插件
                hiprint.init();
                // 打印模板
                let json = {"panels":[{"index":0,"height":100,"width":100,"paperHeader":-15,"paperFooter":283.46456692913387,"printElements":[{"options":{"left":0,"top":16.5,"height":9.75,"width":282,"title":"合箱单号","fontSize":12,"fontWeight":"bold","textAlign":"center"},"printElementType":{"type":"text"}},{"options":{"left":13.5,"top":57,"height":82.5,"width":253.5,"field":"order_no","testData":"1989667129131240769","fontSize":15,"textAlign":"center","lineHeight":19.5,"textType":"barcode"},"printElementType":{"type":"text"}}],"paperNumberLeft":253.5,"paperNumberTop":261,"paperNumberDisabled":true}]};

                // 打印渲染数据
                let jsonData = {order_no: data.express_no};

                // 实例化并打印
                var hiprintTemplate = new hiprint.PrintTemplate({ template:  json});
                hiprintTemplate.print(jsonData);
            }
        })

    });
</script>

<script type="text/html" id="toolbar">
    <!--{if auth("add")}-->
    <a class="layui-btn layui-btn-sm layui-btn-normal" data-title="{:lang('添加合箱')}" data-area="['{{maxWidth-300}}px', '{{maxHeight-100}}px']" data-offset="['60px','250px']" data-modal="{:url('add')}">{:lang('添加合箱')}</a>
    <!--{/if}-->
</script>

<script type="text/html" id="operator_bar">
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print_btn">{:lang('打印合箱单号')}</a>
    <!--{if auth("detail")}-->
    <a class="layui-btn layui-btn-xs layui-btn-normal" data-title="{:lang('查看详情')}" data-area="['{{maxWidth-300}}px', '{{maxHeight-100}}px']" data-offset="['60px','250px']" data-modal='{:url("detail")}?id={{d.id}}'>{:lang('详 情')}</a>
    <!--{/if}-->

    <!--{if auth("splitPacking")}-->
    <a class="layui-btn layui-btn-xs" data-confirm="{:lang('确认拆箱操作吗')}" data-action="{:url('splitPacking')}" data-value="id#{{d.id}}">{:lang('拆 箱')}</a>
    <!--{/if}-->
</script>
{/block}
